<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
    <title>Chọn ảnh</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body >
<div>

    <?php
    if(isset($_GET['path'])) {
        $path = $_GET['path'];
        echo('<p><a href="dialogImage.php"><img src="images/back.png" alt="" width="40px"> </a></p>');
    } else {
        $path = '../FileUpload/';
    }
    $dem = 0;
    $files = array();
    if ($handle = opendir($path)) {
        while (false !== ($file = readdir($handle))) {
            if ($file != "." && $file != ".." && ((preg_match("/\.jpg|\.gif|\.png/i",$file)) || is_dir($path . $file))) {
                $dem++;
                array_push($files,$file);
            }
        }
        closedir($handle);
    }
    if($dem == 0)
    {  ?>
        <p style="color: #ff0000;font-size: 16px"> Không có ảnh nào! <p>
						<?php
    } else {

        foreach($files as $file){
            if ($file != "." && $file != ".." && (preg_match("/\.jpg|\.gif|\.png/i",$file))) {
            ?>
                <div style="display: block;margin: 10px;width: 200px ; height: 150px; float: left">
                    <a  onclick="OK('<?php echo $path . $file; ?>');"><img src="<?php echo $path . $file; ?>" height="150px" width="200px" />
                    </a>
                </div>
        <?php
            } else if (is_dir($path . $file)){
        ?>
                <div style="text-align: center;display: block;float: left;margin: 10px;width: 200px ; height: 150px;">
                    <div class="album">
                        <a href="dialogImage.php?path=<?php echo ($path . $file . "/");?>">
                            <img src="<?php	echo "images/folder.jpg";?>" alt="image" >
                        </a>
                    </div>

                        <a href="dialogImage.php?path=<?php echo $path .$file . "/";?>"> <?php echo "$file" ;?></a>

                </div>
    <?php
        }
    }}
    ?>

</div>
</body>
</html>
<script type="text/javascript">
 function OK(link)
 {
     var vReturnValue = new Object();
     vReturnValue.link = link;

     window.returnValue = vReturnValue;
     window.close();
 }
</script>